{include file="common/public/header"}
<style>
    .active {
        background: #FF5722;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card">
            <div class="layui-card-header">搜索</div>
            <div class="layui-card-body">
                <form   class="layui-form layui-search" >

                    <div class="layui-form-item">
                        <label class="layui-form-label">订单编号</label>
                        <div class="layui-input-block" style="width: 30%;">
                            <input type="text" name="order_sn"  style="width: 100%" autocomplete="off" placeholder="请输入订单编号" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-block" style="width: 30%;">
                          <input type="text" name="date_search" id="date_search" readonly class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">订单状态</label>
                        <div class="layui-input-block">
                            <div class="layui-inline">
                            <div class="layui-btn status layui-btn-sm layui-btn-normal" data-status="">全部 <span class="layui-badge">{$count|default=0}</span> </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn  layui-btn-sm status layui-btn-primary" data-status="0">未支付 <span class="layui-badge">{$count0|default=0}</span></div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn layui-btn-sm status layui-btn-primary" data-status="1">待发货 <span class="layui-badge">{$count1|default=0}</span></div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn layui-btn-sm status layui-btn-primary" data-status="2">待收货 <span class="layui-badge">{$count2|default=0}</span></div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn status  layui-btn-sm layui-btn-primary" data-status="3">已完成 <span class="layui-badge">{$count3|default=0}</span></div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn status  layui-btn-sm layui-btn-primary" data-status="-1">申请退款 <span class="layui-badge">{$count4|default=0}</span></div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn status layui-btn-sm layui-btn-primary" data-status="-2">退款通过 <span class="layui-badge">{$count5|default=0}</span></div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn status layui-btn-sm layui-btn-primary" data-status="-3">退款拒绝 <span class="layui-badge">{$count6|default=0}</span></div>
                            </div>
                        </div>
                        
                     
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                         <div class="layui-input-block">
                            <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" onclick="table_search(this)"><i class="layui-icon layui-icon-search"></i>搜索</button>
                            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-star layuiadmin-button-btn"></i>重置</button>  
                         </div>
                       
                     </div>
                </form>
            </div>
        </div>
        
    </div>
</div>
<div class="layui-fluid">
  
    <div class="layui-row layui-col-space15">
        <div class="layui-card">
          <div class="layui-card-header">{$page_title}</div>
            <div class="layui-card-body">
                
                <table id="table" lay-filter="table"></table>
                <script type="text/html" id="pid">
                    <a href="{:Url('index')}?pid={{d.id}}">查看</a>
                </script>
                <script type="text/html" id="is_show">
                    <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show'  lay-text='显|隐'  {{ d.is_show == 1 ? 'checked' : '' }}>
                </script>
                 <!--订单状态-->
                    <script type="text/html" id="status">
                        {{d.status_name}}
                    </script>
                 <!--商品信息-->
                    <script type="text/html" id="info">
                        {{#  layui.each(d.cart_detail, function(index, item){ }}
                        {{#  if(item.cart_info.productInfo.attrInfo!=undefined){ }}
                        <div style="display: flex">
                            <span style="margin-right: 10px">
                                <img style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                                     src="{{item.cart_info.productInfo.attrInfo.image}}">
                            </span>
                            <span>{{item.cart_info.productInfo.store_name}}&nbsp;{{item.cart_info.productInfo.attrInfo.suk}}</span>
                            <span> | ￥{{item.cart_info.truePrice}}×{{item.cart_info.cart_num}}</span>
                        </div>
                        {{#  }else{ }}
                        <div style="display: flex">
                            <span style="margin-right: 10px"><img style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                                       src="{{item.cart_info.productInfo.image}}"></span>
                            <span>{{item.cart_info.productInfo.store_name}}</span><span> | ￥{{item.cart_info.truePrice}}×{{item.cart_info.cart_num}}</span>
                        </div>
                        {{# } }}
                        {{#  }); }}
                    </script>
                    <script type="text/html" id="act">    
                        {:table_button('admin/Order/detail','订单详情','frame','',['950px','680px'],'','layui-btn-xs')}   
                        {:table_button('admin/Order/order_log','操作记录','frame','',['950px','680px'],'','layui-btn-xs','1')} 

                       {{# if(d.paid==0 && d.status==0 && d.refund_status == 0){ }}
                            <!--未支付-->
                            {:table_button('admin/Order/edit','修改订单','frame','',['950px','680px'],'','layui-btn-xs','1')}
                       {{# }else if(d.paid ==1 && d.status ==0 && d.refund_status==0){ }}
                              <!--已支付 待发货-->
                             {:table_button('admin/Order/deliver','订单发货','frame','',['750px','450px'],'','layui-btn-xs','1')}
                       {{# }else if(d.paid ==1 && d.status ==1 && d.refund_status ==0){ }}
                              <!--已发货 待收货-->
                             {:table_button('admin/Order/distribution','物流信息','frame','',['750px','450px'],'','layui-btn-xs','1')}
                       {{# }else if(d.paid ==1 && d.status ==2 && d.refund_status ==0){ }}
                            <!--已收货 订单完成-->

                       {{# }else if(d.paid ==1 && d.refund_status ==1){ }}
                              <!-- 申请退款-->
                            {:table_button('admin/Order/refund_y','通过退款','frame','',['450px','300px'],'','layui-btn-xs')}
                            {:table_button('admin/Order/refund_n','拒绝退款','frame','',['450px','300px'],'','layui-btn-xs')}
                        {{# }  }}
                               

                      
                    </script>

            </div>
        </div>

    </div>
</div>
{include file="common/public/footer" /}
{include file="common/public/table" /}
<script>
    layui.use(['index', 'form', 'table','laydate'], function(){
        var $       = layui.$;
        var table   = layui.table;
        var  form   = layui.form;
        var laydate = layui.laydate;
      var tableIns =   table.render({
        elem: '#table'
        ,url: "index" //数据接口
        ,page: true //开启分页
        ,method:'POST'
        ,defaultToolbar: []
        ,cols: [[ //表头
            {field: 'order_id', title: '订单号', event: 'order_id', width: '14%',},
            {field: 'nickname', title: '用户信息', width: '10%', align: 'center'},
            {field: 'info', title: '商品信息', templet: "#info", height: 'full-20'},
            {field: 'pay_price', title: '实际支付', width: '8%', align: 'center'},
            {field: 'status', title: '订单状态', templet: '#status', width: '8%', align: 'center'},
            {field: 'add_time', title: '下单时间', width: '10%',align: 'center'},
            {field: 'right', title: '操作', align: 'center', toolbar: '#act',width: '10%'},
        ]]
    });
     laydate.render({
            elem: '#date_search' //指定元素
            ,range:'~'
            ,trigger:'click'
            ,type:'datetime'
        });
    form.on('switch(is_show)', function(data) {
            var url = "{:url('admin/StoreCategory/is_show')}";
            Post(url, {checked: $(data.elem).is(":checked") ? 1: 0,id:data.value}, function(res) {
                if(res.code == 1) {
                    table_reload();
                }else {
                    alert_error(res.msg);
                }
            });
        });
  $('.status').click(function(){
            var status = $(this).data('status');
            $('.status').attr("class", 'layui-btn layui-btn-sm layui-btn-primary status');
            $(this).removeClass('layui-btn-primary');
            $(this).addClass('layui-btn-normal');
            table.reload('table',{
                url:'index',
                where:{'status':status}
            }, true);
        })
  
});
</script>